import org.eclipse.swt.graphics.Point;

import org.eclipse.swt.graphics.GC;


public class LineDummy {
	
	public int x1;
	public int x2;
	public int y1;
	public int y2;
	
	public int a;
	public int b;
	public int c;
	
	public int x;
	public int y;
	
	public LineDummy(int x1, int y1, int x2, int y2){
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
		
		a = y2 - y1;
		b = x1 - x2;
		c = -1 * a * x1 - b * a;
	}
	
	public LineDummy(int a, int b, int c){
		this.a = a;
		this.b = b;
		this.c = c;
	}
	
	public boolean intersect2(LineDummy line2){
		
		double am = this.a / line2.a;
		double bm = this.b / line2.b;
		
		if (am != bm){
			
			return true;
		}
		else
			return false;
	}
	
	public void paint(GC gc){
		gc.drawLine(x1, y1, x2, y2);
	}
	
	public boolean intersect(LineDummy line2){
		int x3 = line2.x1;
		int x4 = line2.x2;
		int y3 = line2.y1;
		int y4 = line2.y2;
		
		int vector_prod1 = (x2 - x1)*(y3 - y1) - (x3 - x1)*(y2 - y1);
		   //Vector product of vectors 1_2 and 1_4
		int vector_prod2 = (x2 - x1)*(y4 - y1) - (x4 - x1)*(y2 - y1);
		if(vector_prod1*vector_prod2 > 0)
			return false;
			
		   //Vector product of vectors 3_4 and 3_1
		int vector_prod3 = (x4 - x3)*(y1 - y3) - (x1 - x3)*(y4 - y3);
		   //Vector product of vectors 3_4 and 3_2
		int vector_prod4 = (x4 - x3)*(y2 - y3) - (x2 - x3)*(y4 - y3);
		if(vector_prod3*vector_prod4 > 0)
		     return false;
		return true;
	}
	

	
	public Point intersectPoint(LineDummy line2){
		int x3 = line2.x1;
		int x4 = line2.x2;
		int y3 = line2.y1;
		int y4 = line2.y2;
		
		double d = (x1 - x2) * (y4 - y3) - (y1 - y2) * (x4 - x3);
		double da = (x1 - x3) * (y4 - y3) - (y1 - y3) * (x4 - x3);
		double db = (x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3);
	 
		double ta = da / d;
		double tb = db / d;
	 
		if (ta >= 0 && ta <= 1 && tb >= 0 && tb <= 1)
		{
			double dx = x1 + ta * (x2 - x1);
			double dy = y1 + ta * (y2 - y1);
	 
			int dxx = (int) dx;
			int dyy = (int) dy;
			
			return new Point(dxx, dyy);
		}
	 
		return null;
	}
}
